package graduation.claf.tools;


import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Date;

/**
 * 时间格式化
 */
public class DateUtil {

    public static final String STANDRAD="yyyy-MM-dd HH:mm:ss";

    //字符串转Date类型
    public static Date string2Date(String strDate){
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDRAD);
        return dateTimeFormatter.parseDateTime(strDate).toDate();
    }

    //Date类型转字符串
    public static String date2String(Date date){
        if (date == null){
            return StringUtils.EMPTY;
        }
        DateTime dateTime = new DateTime(date);
        return dateTime.toString(STANDRAD);
    }
}
